package cn.ly.core.inclass;

import java.util.Comparator;

public class PartOuterClass {
	
	private String outName;
	public PartOuterClass(String name){
		this.outName = name;
	}
	
	private void callName(){
		System.out.println(this.outName);
	}
	
	public String getName(){
		return this.outName;
	}
	
	public void changeName(final String newName){
		int a = 1;
		final int b = 2;
		class InnerClass{
			public InnerClass(){
				
			}
			public int geta(){  //只能访问方法体内的final的局部变量，其它编译报错????????
				return a;
			}
			public int getFinalb(){
				return b;
			}
			public String getOutName(){
				PartOuterClass.this.outName = newName;
				return PartOuterClass.this.outName;
			}
			public void callOutName(){
				PartOuterClass.this.callName();
			}
		}
		InnerClass in = new InnerClass();
		System.out.println(in.geta());
		System.out.println(in.getFinalb());
		in.callOutName();
		System.out.println(in.getOutName());
		in.callOutName();
	}
	
	public int compare(PartOuterClass p){  //不需在麻烦写一个比较器的类，去实现这种类型的比较，屏蔽类的定义
		class PartCompartor implements Comparator<PartOuterClass>{
			@Override
			public int compare(PartOuterClass o1, PartOuterClass o2) {
				return o1.getName().compareTo(o2.getName());
			}
		}
		PartCompartor c = new PartCompartor();
		return c.compare(PartOuterClass.this, p);
	}
	
	public static void main(String[] args) {
		PartOuterClass p1 = new PartOuterClass("张3");
		p1.changeName("李a");
		PartOuterClass p2 = new PartOuterClass("李b");
		System.out.println(p1.compare(p2));
		
	}

}
